package com.ruoyi.assessLog.controller;

import com.ruoyi.assessLog.domain.AssessLog;
import com.ruoyi.assessLog.service.IAssessLogService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 出入日志Controller
 * 
 * @author 张柏焰
 * @date 2024-07-09
 */
@RestController
@RequestMapping("/assessLog/assessLog")
public class AssessLogController extends BaseController
{
    @Autowired
    private IAssessLogService assessLogService;

    /**
     * 查询出入日志列表
     */
    @PreAuthorize("@ss.hasPermi('assessLog:assessLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssessLog assessLog)
    {
        startPage();
        List<AssessLog> list = assessLogService.selectAssessLogList(assessLog);
        return getDataTable(list);
    }

    /**
     * 导出出入日志列表
     */
    @PreAuthorize("@ss.hasPermi('assessLog:assessLog:export')")
    @Log(title = "出入日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssessLog assessLog)
    {
        List<AssessLog> list = assessLogService.selectAssessLogList(assessLog);
        ExcelUtil<AssessLog> util = new ExcelUtil<AssessLog>(AssessLog.class);
        util.exportExcel(response, list, "出入日志数据");
    }

    /**
     * 获取出入日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('assessLog:assessLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assessLogService.selectAssessLogById(id));
    }

    /**
     * 新增出入日志
     */
    @PreAuthorize("@ss.hasPermi('assessLog:assessLog:add')")
    @Log(title = "出入日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssessLog assessLog)
    {
        return toAjax(assessLogService.insertAssessLog(assessLog));
    }

    /**
     * 修改出入日志
     */
    @PreAuthorize("@ss.hasPermi('assessLog:assessLog:edit')")
    @Log(title = "出入日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssessLog assessLog)
    {
        return toAjax(assessLogService.updateAssessLog(assessLog));
    }

    /**
     * 删除出入日志
     */
    @PreAuthorize("@ss.hasPermi('assessLog:assessLog:remove')")
    @Log(title = "出入日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assessLogService.deleteAssessLogByIds(ids));
    }

    @GetMapping("/getList")
    public AjaxResult getList()
    {
        AssessLog assessLog  = new AssessLog();
        List<AssessLog> list = assessLogService.selectAssessLogList(assessLog);
        int returnList[] = new int[4];
        for (AssessLog assess: list) {
            Number num = assess.getAssess();
            Number num2 = assess.getPersonType();
            returnList[num.intValue()]++;
            if(num2.intValue() == 0 )
            {
                returnList[2]++;
            }
            else
            {
                returnList[3]++;
            }
        };

        return success(returnList);
    }
}
